package com.ymatou.run;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;

import android.os.RemoteException;

import com.android.uiautomator.core.UiDevice;

@SuppressWarnings("deprecation")
public class UiDeviceUtil{
	
	//private static final String TAG = UiDeviceUtil.class.getSimpleName();
	RunTestCase runTestCase = new RunTestCase();
	
	public UiDevice getUiDeviceInstance() {
		return UiDevice.getInstance();
	}
	
	public void swpie(int startX, int startY, int endX, int endY, int steps) {
		getUiDeviceInstance().swipe(startX, startY, endX, endY, steps);
	}
	
	public void wakeUp() throws RemoteException {
		if (!getUiDeviceInstance().isScreenOn()) {
			getUiDeviceInstance().wakeUp();
		}
	}
	
	public void pressHome() {
		getUiDeviceInstance().pressBack();
	}
	
	public void takeScreenSnapShot() throws InterruptedException {
		//创建保存图片的文件夹
		File file = new File("/mnt/sdcard/UiAutomatorSnapShot/");
		
		Date a = new Date();  
		SimpleDateFormat b = new SimpleDateFormat("yyyy-MM-dd_HHmmss");  
		String fileName = b.format(a) + ".png";
		File files = new File(file.getAbsolutePath() + "/" + fileName);
		if (!file.exists()) {
			file.mkdirs();
			
			getUiDeviceInstance().takeScreenshot(files);
		} else {
			getUiDeviceInstance().takeScreenshot(files);
		}
	}
}
